class CollectionUtil {
    static contains = (arr, obj, key) => {
        let i = arr.length;
        if (i == 0) return false;
        while (i--) {
            if (arr[i][key] === obj[key]) {
                return true;
            }
        }
        return false;
    }
        static getItemByKey = (arr, obj, key) => {
            let i = arr.length;
            if (i == 0) return false;
            while (i--) {
                if (arr[i][key] === obj[key]) {
                    return arr[i];
                }
            }
            return null;
        }

    static remove = (arr, val) => {
        const index = arr.indexOf(val);
        if (index > -1) {
            arr.splice(index, 1);
        }
    };

    static removeByAttributeName = (objectList, attributeName, value) => {
        let index = 0;
        for (let i = 0; i < objectList.length; i++) {
            if (objectList[i][attributeName] == value) {
                index = i;
                break;
            }
        }
        objectList.splice(index, 1);
    };

    static getItemByAttributeName = (objectList, attributeName, value) => {
        if (objectList == null || objectList.length == 0) {
            return null;
        }
        const index = 0;
        for (let i = 0; i < objectList.length; i++) {
            if (objectList[i][attributeName] == value) {
                return objectList[i];
            }
        }
        return null;
    };
    static modifyItemByAttributeName = (objectList, attributeName, value1, newAttribute, value2) => {
        const index = 0;
        for (let i = 0; i < objectList.length; i++) {
            if (objectList[i][attributeName] == value1) {
                objectList[i][newAttribute] = value2;
            }
        }
    };

    static unique(arr) {
        const res = [];
        const json = {};
        for (let i = 0; i < arr.length; i++) {
            if (!json[arr[i]]) {
                res.push(arr[i]);
                json[arr[i]] = 1;
            }
        }
        return res;
    }
}
export default CollectionUtil;
